package com.stack.knowyoubase.util;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类
 *
 * @author stack
 */
@Component
@Scope("singleton")
public class TimeUtil {
    public boolean isEffectiveDate(String endDate) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        try {
            Date endTime = format.parse(endDate);
            Date nowTime = new Date();
            if (nowTime.getTime() == endTime.getTime()) {
                //没有超时
                return true;
            }
            Calendar now = Calendar.getInstance();
            now.setTime(nowTime);
            Calendar end = Calendar.getInstance();
            end.setTime(endTime);
            if (now.before(end)) {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
        return false;
    }

    public static void main(String[] args) {
        TimeUtil timeUtil = new TimeUtil();
        System.out.println(timeUtil.isEffectiveDate("2020-07-06 16:40:00"));
        System.out.println(timeUtil.isEffectiveDate("2020-07-06 16:55:00"));

    }
}
